local sk__kunfen = fk.CreateSkill {

  name = "sk__kunfen",

  tags = { Skill.Compulsory, },

}



sk__kunfen:addEffect(fk.Damaged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__kunfen.name) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(3, sk__kunfen.name)
    if player:usedSkillTimes(sk__kunfen.name, Player.HistoryTurn) == 1 and not player.dead and player:isWounded() then
      player.room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = sk__kunfen.name,
      })
    end
  end,
})
sk__kunfen:addEffect(fk.HpLost, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__kunfen.name) then
      return data.num < 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(3, sk__kunfen.name)
    if player:usedSkillTimes(sk__kunfen.name, Player.HistoryTurn) == 1 and not player.dead and player:isWounded() then
      player.room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = sk__kunfen.name,
      })
    end
  end,
})
sk__kunfen:addEffect(fk.MaxHpChanged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__kunfen.name) then
      return data.num < 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(3, sk__kunfen.name)
    if player:usedSkillTimes(sk__kunfen.name, Player.HistoryTurn) == 1 and not player.dead and player:isWounded() then
      player.room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = sk__kunfen.name,
      })
    end
  end,
})

return sk__kunfen